﻿$(function() {
	$('#history_data').datagrid({    
	    url: basePath+"/resources/json/history.json",
	    method: 'get',
	    striped : true,
		nowrap : true,
		rownumbers : true,
		fitColumns : true,
		border:false,
		scrollbarSize:1,
	    columns:[[
	        {field:'ck',checkbox:true},
			{field:'datatime',align:'center','title':'抄表时刻',width:200},
			{field:'data',align:'center','title':'抄表读数(KW/h)',width:150},
			{field:'power',align:'center','title':'功率(w)',width:100},
			{field:'speed',align:'center','title':'主轴转速(r/min)',width:150},
			{field:'feed',align:'center','title':'进给速率(mm/min)',width:150},
			{field:'deep',align:'center','title':'铁销深度(mm)',width:150},
			{field:'wd',align:'center','title':'铁销宽度(mm)',width:150},
			{field:'diameter',align:'center','title':'刀具直径(mm)',width:150}
	    ]],
	    pagination : true,
  		pageList : [6,12,18],
  		pageNumber : 1,
		pageSize : 18,
  		pagePosition : 'bottom',
  		loadFilter:pagerFilter
	});
});

function pagerFilter(data){
	if (typeof data.length == 'number' && typeof data.splice == 'function'){	// is array
		data = {
			total: data.length,
			rows: data
		}
	}
	var dg = $(this);
	var opts = dg.datagrid('options');
	var pager = dg.datagrid('getPager');
	pager.pagination({
		onSelectPage:function(pageNum, pageSize){
			opts.pageNumber = pageNum;
			opts.pageSize = pageSize;
			pager.pagination('refresh',{
				pageNumber:pageNum,
				pageSize:pageSize
			});
			dg.datagrid('loadData',data);
		}
	});
	if (!data.originalRows){
		data.originalRows = (data.rows);
	}
	var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
	var end = start + parseInt(opts.pageSize);
	data.rows = (data.originalRows.slice(start, end));
	return data;
}